/**
 * 公共文件
 */
import { Modal } from 'antd';
import { ExclamationCircleOutlined, QuestionCircleOutlined } from '@ant-design/icons';

/**
 * confirm
 * @param {*} message 要提示的消息
 * @param {*} title 标题
 */
export const confirm = (message, title = '询问') => {
    return new Promise((res, rej) => {
        Modal.confirm({
            title: title,
            icon: <ExclamationCircleOutlined />,
            content: message,
            okText: '确认',
            cancelText: '取消',
            onCancel: close => {
                close();
                rej();
            },
            onOk: close => {
                close();
                res();
            }
        });
    });
}

/**
 * 异步confirm
 * @param {*} message 要提示的消息
 * @param {*} title 标题
 * @returns 
 */
export const asyncConfirm = (message, title = '询问') => {
    return new Promise((res, rej) => {
        const m = Modal.confirm({
            title: title,
            icon: <QuestionCircleOutlined />,
            content: message,
            onCancel: close => {
                close();
                rej();
            },
            onOk: () => {
                return new Promise(() => {
                    res({ close: m.destroy })
                });
            }
        });
    });
}